//
//  FaceUseResultModel.swift
//  MM2
//
//  Created by 李成明 on 2022/1/5.
//

class FaceUseResultModel: BaseModel {
    init(model: FaceAnalyzeModel) {
        super.init()
        guard let face = model.faces.first, let attr = face.attributes else { return }
        
        gender = (attr.gender?.value ?? "" == "Female") ? 2 : 1
        faceValue = gender == 2 ? (attr.beauty?.female_score ?? -1) : (attr.beauty?.male_score ?? -1)
        age = attr.age?.value ?? 20
        
        let smileValue = attr.smile?.value ?? 0
        smile = (attr.smile?.threshold ?? 0) > smileValue ? 0 : smileValue
        emotion = attr.emotion?.emotionType ?? .neutral(value: 0)
        skinHealth = attr.skinstatus?.health ?? 50
        skinStain = attr.skinstatus?.stain ?? 50
        skinAcne = attr.skinstatus?.acne ?? 50
        skinDarkCircle = attr.skinstatus?.dark_circle ?? 50
    }
    
    required init() {
        fatalError("init() has not been implemented")
    }
    
    var faceValue: Float = 0
    var gender: Int = 1
    var age: Int = 0
    var smile: Float = 0
    var emotion: EmotionType = .neutral(value: 0)
    var skinHealth: Float = 0
    var skinStain: Float = 0
    var skinAcne: Float = 0
    var skinDarkCircle: Float = 0
    
    func getValueArray() -> [FaceAnalyzeResultType] {
        let emotionValue = emotion.desInt
        
        return [.gender(value: gender), .age(value: age), .smile(value: smile), .emotion(value: emotionValue), .skinHealth(value: skinHealth), .skinStain(value: skinStain), .skinAcne(value: skinAcne), .skinDarkCircle(value: skinDarkCircle)]
    }

}
